import type { ApiResponse } from "@/api/type.ts"
import request from "@/api/config/request.ts"

export interface UserStructure {
  id: number
  username: string
  password: string
  phone: string
  email: string
  avatar: string
  create_time: string
}

export interface UserResponse {
  list: UserStructure[]
  total: number
}

export interface getUserParams {
  username?: string
  page: number
  pageSize: number
}

export const getUserListApi = async (
  data: getUserParams = { page: 1, pageSize: 10 }
): Promise<ApiResponse<UserResponse>> => {
  return request.post("/user/getList", data)
}

export const addUserApi = async (
  data: Partial<UserStructure>
): Promise<ApiResponse<UserStructure>> => {
  return request.post("/user/create", data)
}

export const editUserApi = async (
  data: Partial<UserStructure>
): Promise<ApiResponse<UserStructure>> => {
  return request.post("/user/update", data)
}

export const deleteUserApi = async (
  id: number
): Promise<ApiResponse<UserStructure>> => {
  return request.post("/user/delete", { id })
}
